package org.jeecg.modules.operations.assistant.oa.controller;

import org.jeecg.common.system.query.QueryGenerator;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.system.query.QueryRuleEnum;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.api.vo.Result;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerBorderImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import java.util.Arrays;
import java.util.HashMap;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.operations.assistant.oa.entity.OaOvertimeRecord;
import org.jeecg.modules.operations.assistant.oa.entity.OaAttendanceRecord;
import org.jeecg.modules.operations.assistant.oa.entity.OaMonthlyAttendance;
import org.jeecg.modules.operations.assistant.oa.entity.OaMonthlyOvertime;
import org.jeecg.modules.operations.assistant.oa.entity.OaPaidWages;
import org.jeecg.modules.operations.assistant.oa.entity.OaEmployeeInfo;
import org.jeecg.modules.operations.assistant.oa.service.IOaEmployeeInfoService;
import org.jeecg.modules.operations.assistant.oa.service.IOaOvertimeRecordService;
import org.jeecg.modules.operations.assistant.oa.service.IOaAttendanceRecordService;
import org.jeecg.modules.operations.assistant.oa.service.IOaMonthlyAttendanceService;
import org.jeecg.modules.operations.assistant.oa.service.IOaMonthlyOvertimeService;
import org.jeecg.modules.operations.assistant.oa.service.IOaPaidWagesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.shiro.authz.annotation.RequiresPermissions;
 /**
 * @Description: 员工信息
 * @Author: jeecg-boot
 * @Date:   2024-12-12
 * @Version: V1.0
 */
@Api(tags="员工信息")
@RestController
@RequestMapping("/oa/oaEmployeeInfo")
@Slf4j
public class OaEmployeeInfoController extends JeecgController<OaEmployeeInfo, IOaEmployeeInfoService> {

	@Autowired
	private IOaEmployeeInfoService oaEmployeeInfoService;

	@Autowired
	private IOaOvertimeRecordService oaOvertimeRecordService;

	@Autowired
	private IOaAttendanceRecordService oaAttendanceRecordService;

	@Autowired
	private IOaMonthlyAttendanceService oaMonthlyAttendanceService;

	@Autowired
	private IOaMonthlyOvertimeService oaMonthlyOvertimeService;

	@Autowired
	private IOaPaidWagesService oaPaidWagesService;

	 @Resource
	 private JeecgBaseConfig jeecgBaseConfig;

	/*---------------------------------主表处理-begin-------------------------------------*/

	/**
	 * 分页列表查询
	 * @param oaEmployeeInfo
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "员工信息-分页列表查询")
	@ApiOperation(value="员工信息-分页列表查询", notes="员工信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<OaEmployeeInfo>> queryPageList(OaEmployeeInfo oaEmployeeInfo,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
      	QueryWrapper<OaEmployeeInfo> queryWrapper = QueryGenerator.initQueryWrapper(oaEmployeeInfo, req.getParameterMap());
		Page<OaEmployeeInfo> page = new Page<OaEmployeeInfo>(pageNo, pageSize);
		IPage<OaEmployeeInfo> pageList = oaEmployeeInfoService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
     *   添加
     * @param oaEmployeeInfo
     * @return
     */
    @AutoLog(value = "员工信息-添加")
    @ApiOperation(value="员工信息-添加", notes="员工信息-添加")
    @RequiresPermissions("oa:oa_employee_info:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody OaEmployeeInfo oaEmployeeInfo) {
        oaEmployeeInfoService.save(oaEmployeeInfo);
        return Result.OK("添加成功！");
    }

    /**
     *  编辑
     * @param oaEmployeeInfo
     * @return
     */
    @AutoLog(value = "员工信息-编辑")
    @ApiOperation(value="员工信息-编辑", notes="员工信息-编辑")
    @RequiresPermissions("oa:oa_employee_info:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> edit(@RequestBody OaEmployeeInfo oaEmployeeInfo) {
        oaEmployeeInfoService.updateById(oaEmployeeInfo);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @AutoLog(value = "员工信息-通过id删除")
    @ApiOperation(value="员工信息-通过id删除", notes="员工信息-通过id删除")
    @RequiresPermissions("oa:oa_employee_info:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        oaEmployeeInfoService.delMain(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @AutoLog(value = "员工信息-批量删除")
    @ApiOperation(value="员工信息-批量删除", notes="员工信息-批量删除")
    @RequiresPermissions("oa:oa_employee_info:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.oaEmployeeInfoService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     * @return
     */
    @RequiresPermissions("oa:oa_employee_info:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, OaEmployeeInfo oaEmployeeInfo) {
//        return super.exportXls(request, oaEmployeeInfo, OaEmployeeInfo.class, "员工信息");
		// Step.1 组装查询条件
		QueryWrapper<OaEmployeeInfo> queryWrapper = QueryGenerator.initQueryWrapper(oaEmployeeInfo, request.getParameterMap());
		LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		// 过滤选中数据
		String selections = request.getParameter("selections");
		if (oConvertUtils.isNotEmpty(selections)) {
			List<String> selectionList = Arrays.asList(selections.split(","));
			queryWrapper.in("id",selectionList);
		}
		// Step.2 获取导出数据
		List<OaEmployeeInfo> exportList = service.list(queryWrapper);

		// Step.3 AutoPoi 导出Excel
		ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		//此处设置的filename无效 ,前端会重更新设置一下
		mv.addObject(NormalExcelConstants.FILE_NAME, "乐山市鸿源劳务有限公司员工工资表");
		mv.addObject(NormalExcelConstants.CLASS, OaEmployeeInfo.class);
		//update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
		ExportParams exportParams=new ExportParams("乐山市鸿源劳务有限公司员工工资" + "表", "导出人:" + sysUser.getRealname(), "员工工资表");
		exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
		exportParams.setStyle(ExcelExportStylerBorderImpl.class);
		//update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
		mv.addObject(NormalExcelConstants.PARAMS,exportParams);
		mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequiresPermissions("oa:oa_employee_info:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, OaEmployeeInfo.class);
    }
	/*---------------------------------主表处理-end-------------------------------------*/
	

    /*--------------------------------子表处理-加班记录-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "加班记录-通过主表ID查询")
	@ApiOperation(value="加班记录-通过主表ID查询", notes="加班记录-通过主表ID查询")
	@GetMapping(value = "/listOaOvertimeRecordByMainId")
    public Result<IPage<OaOvertimeRecord>> listOaOvertimeRecordByMainId(OaOvertimeRecord oaOvertimeRecord,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<OaOvertimeRecord> queryWrapper = QueryGenerator.initQueryWrapper(oaOvertimeRecord, req.getParameterMap());
        Page<OaOvertimeRecord> page = new Page<OaOvertimeRecord>(pageNo, pageSize);
        IPage<OaOvertimeRecord> pageList = oaOvertimeRecordService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param oaOvertimeRecord
	 * @return
	 */
	@AutoLog(value = "加班记录-添加")
	@ApiOperation(value="加班记录-添加", notes="加班记录-添加")
	@PostMapping(value = "/addOaOvertimeRecord")
	public Result<String> addOaOvertimeRecord(@RequestBody OaOvertimeRecord oaOvertimeRecord) {
		oaOvertimeRecordService.saveOaOvertimeRecord(oaOvertimeRecord);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param oaOvertimeRecord
	 * @return
	 */
	@AutoLog(value = "加班记录-编辑")
	@ApiOperation(value="加班记录-编辑", notes="加班记录-编辑")
	@RequestMapping(value = "/editOaOvertimeRecord", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editOaOvertimeRecord(@RequestBody OaOvertimeRecord oaOvertimeRecord) {
		oaOvertimeRecordService.updateById(oaOvertimeRecord);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "加班记录-通过id删除")
	@ApiOperation(value="加班记录-通过id删除", notes="加班记录-通过id删除")
	@DeleteMapping(value = "/deleteOaOvertimeRecord")
	public Result<String> deleteOaOvertimeRecord(@RequestParam(name="id",required=true) String id) {
		oaOvertimeRecordService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "加班记录-批量删除")
	@ApiOperation(value="加班记录-批量删除", notes="加班记录-批量删除")
	@DeleteMapping(value = "/deleteBatchOaOvertimeRecord")
	public Result<String> deleteBatchOaOvertimeRecord(@RequestParam(name="ids",required=true) String ids) {
	    this.oaOvertimeRecordService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportOaOvertimeRecord")
    public ModelAndView exportOaOvertimeRecord(HttpServletRequest request, OaOvertimeRecord oaOvertimeRecord) {
		 // Step.1 组装查询条件
		 QueryWrapper<OaOvertimeRecord> queryWrapper = QueryGenerator.initQueryWrapper(oaOvertimeRecord, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<OaOvertimeRecord> pageList = oaOvertimeRecordService.list(queryWrapper);
		 List<OaOvertimeRecord> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "加班记录");
		 mv.addObject(NormalExcelConstants.CLASS, OaOvertimeRecord.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("加班记录报表", "导出人:" + sysUser.getRealname(), "加班记录"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importOaOvertimeRecord/{mainId}")
    public Result<?> importOaOvertimeRecord(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<OaOvertimeRecord> list = ExcelImportUtil.importExcel(file.getInputStream(), OaOvertimeRecord.class, params);
				 for (OaOvertimeRecord temp : list) {
                    temp.setEmployeeInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 oaOvertimeRecordService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-加班记录-end----------------------------------------------*/

    /*--------------------------------子表处理-考勤记录-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "考勤记录-通过主表ID查询")
	@ApiOperation(value="考勤记录-通过主表ID查询", notes="考勤记录-通过主表ID查询")
	@GetMapping(value = "/listOaAttendanceRecordByMainId")
    public Result<IPage<OaAttendanceRecord>> listOaAttendanceRecordByMainId(OaAttendanceRecord oaAttendanceRecord,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<OaAttendanceRecord> queryWrapper = QueryGenerator.initQueryWrapper(oaAttendanceRecord, req.getParameterMap());
        Page<OaAttendanceRecord> page = new Page<OaAttendanceRecord>(pageNo, pageSize);
        IPage<OaAttendanceRecord> pageList = oaAttendanceRecordService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param oaAttendanceRecord
	 * @return
	 */
	@AutoLog(value = "考勤记录-添加")
	@ApiOperation(value="考勤记录-添加", notes="考勤记录-添加")
	@PostMapping(value = "/addOaAttendanceRecord")
	public Result<String> addOaAttendanceRecord(@RequestBody OaAttendanceRecord oaAttendanceRecord) {
		oaAttendanceRecordService.saveOaAttendanceRecord(oaAttendanceRecord);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param oaAttendanceRecord
	 * @return
	 */
	@AutoLog(value = "考勤记录-编辑")
	@ApiOperation(value="考勤记录-编辑", notes="考勤记录-编辑")
	@RequestMapping(value = "/editOaAttendanceRecord", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editOaAttendanceRecord(@RequestBody OaAttendanceRecord oaAttendanceRecord) {
		oaAttendanceRecordService.updateById(oaAttendanceRecord);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "考勤记录-通过id删除")
	@ApiOperation(value="考勤记录-通过id删除", notes="考勤记录-通过id删除")
	@DeleteMapping(value = "/deleteOaAttendanceRecord")
	public Result<String> deleteOaAttendanceRecord(@RequestParam(name="id",required=true) String id) {
		oaAttendanceRecordService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "考勤记录-批量删除")
	@ApiOperation(value="考勤记录-批量删除", notes="考勤记录-批量删除")
	@DeleteMapping(value = "/deleteBatchOaAttendanceRecord")
	public Result<String> deleteBatchOaAttendanceRecord(@RequestParam(name="ids",required=true) String ids) {
	    this.oaAttendanceRecordService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportOaAttendanceRecord")
    public ModelAndView exportOaAttendanceRecord(HttpServletRequest request, OaAttendanceRecord oaAttendanceRecord) {
		 // Step.1 组装查询条件
		 QueryWrapper<OaAttendanceRecord> queryWrapper = QueryGenerator.initQueryWrapper(oaAttendanceRecord, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<OaAttendanceRecord> pageList = oaAttendanceRecordService.list(queryWrapper);
		 List<OaAttendanceRecord> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "乐山时鸿源劳务有限公司考勤记录");
		 mv.addObject(NormalExcelConstants.CLASS, OaAttendanceRecord.class);
		 ExportParams exportParams = new ExportParams("乐山时鸿源劳务有限公司考勤记录报表", "导出人:" + sysUser.getRealname(), "考勤记录");
		 exportParams.setStyle(ExcelExportStylerBorderImpl.class);
		 mv.addObject(NormalExcelConstants.PARAMS, exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importOaAttendanceRecord/{mainId}")
    public Result<?> importOaAttendanceRecord(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<OaAttendanceRecord> list = ExcelImportUtil.importExcel(file.getInputStream(), OaAttendanceRecord.class, params);
				 for (OaAttendanceRecord temp : list) {
                    temp.setEmployeeInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 oaAttendanceRecordService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-考勤记录-end----------------------------------------------*/

    /*--------------------------------子表处理-考勤统计-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "考勤统计-通过主表ID查询")
	@ApiOperation(value="考勤统计-通过主表ID查询", notes="考勤统计-通过主表ID查询")
	@GetMapping(value = "/listOaMonthlyAttendanceByMainId")
    public Result<IPage<OaMonthlyAttendance>> listOaMonthlyAttendanceByMainId(OaMonthlyAttendance oaMonthlyAttendance,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<OaMonthlyAttendance> queryWrapper = QueryGenerator.initQueryWrapper(oaMonthlyAttendance, req.getParameterMap());
        Page<OaMonthlyAttendance> page = new Page<OaMonthlyAttendance>(pageNo, pageSize);
        IPage<OaMonthlyAttendance> pageList = oaMonthlyAttendanceService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param oaMonthlyAttendance
	 * @return
	 */
	@AutoLog(value = "考勤统计-添加")
	@ApiOperation(value="考勤统计-添加", notes="考勤统计-添加")
	@PostMapping(value = "/addOaMonthlyAttendance")
	public Result<String> addOaMonthlyAttendance(@RequestBody OaMonthlyAttendance oaMonthlyAttendance) {
		oaMonthlyAttendanceService.save(oaMonthlyAttendance);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param oaMonthlyAttendance
	 * @return
	 */
	@AutoLog(value = "考勤统计-编辑")
	@ApiOperation(value="考勤统计-编辑", notes="考勤统计-编辑")
	@RequestMapping(value = "/editOaMonthlyAttendance", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editOaMonthlyAttendance(@RequestBody OaMonthlyAttendance oaMonthlyAttendance) {
		oaMonthlyAttendanceService.updateById(oaMonthlyAttendance);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "考勤统计-通过id删除")
	@ApiOperation(value="考勤统计-通过id删除", notes="考勤统计-通过id删除")
	@DeleteMapping(value = "/deleteOaMonthlyAttendance")
	public Result<String> deleteOaMonthlyAttendance(@RequestParam(name="id",required=true) String id) {
		oaMonthlyAttendanceService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "考勤统计-批量删除")
	@ApiOperation(value="考勤统计-批量删除", notes="考勤统计-批量删除")
	@DeleteMapping(value = "/deleteBatchOaMonthlyAttendance")
	public Result<String> deleteBatchOaMonthlyAttendance(@RequestParam(name="ids",required=true) String ids) {
	    this.oaMonthlyAttendanceService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportOaMonthlyAttendance")
    public ModelAndView exportOaMonthlyAttendance(HttpServletRequest request, OaMonthlyAttendance oaMonthlyAttendance) {
		 // Step.1 组装查询条件
		 QueryWrapper<OaMonthlyAttendance> queryWrapper = QueryGenerator.initQueryWrapper(oaMonthlyAttendance, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<OaMonthlyAttendance> pageList = oaMonthlyAttendanceService.list(queryWrapper);
		 List<OaMonthlyAttendance> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "乐山市鸿源劳务有限公司员工考勤统计表");
		 mv.addObject(NormalExcelConstants.CLASS, OaMonthlyAttendance.class);
		 ExportParams exportParams = new ExportParams("乐山市鸿源劳务有限公司员工考勤统计表", "导出人:" + sysUser.getRealname(), "工考勤统计");
		 exportParams.setStyle(ExcelExportStylerBorderImpl.class);
		 mv.addObject(NormalExcelConstants.PARAMS, exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importOaMonthlyAttendance/{mainId}")
    public Result<?> importOaMonthlyAttendance(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<OaMonthlyAttendance> list = ExcelImportUtil.importExcel(file.getInputStream(), OaMonthlyAttendance.class, params);
				 for (OaMonthlyAttendance temp : list) {
                    temp.setEmployeeInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 oaMonthlyAttendanceService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-考勤统计-end----------------------------------------------*/

    /*--------------------------------子表处理-加班统计-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "加班统计-通过主表ID查询")
	@ApiOperation(value="加班统计-通过主表ID查询", notes="加班统计-通过主表ID查询")
	@GetMapping(value = "/listOaMonthlyOvertimeByMainId")
    public Result<IPage<OaMonthlyOvertime>> listOaMonthlyOvertimeByMainId(OaMonthlyOvertime oaMonthlyOvertime,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<OaMonthlyOvertime> queryWrapper = QueryGenerator.initQueryWrapper(oaMonthlyOvertime, req.getParameterMap());
        Page<OaMonthlyOvertime> page = new Page<OaMonthlyOvertime>(pageNo, pageSize);
        IPage<OaMonthlyOvertime> pageList = oaMonthlyOvertimeService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param oaMonthlyOvertime
	 * @return
	 */
	@AutoLog(value = "加班统计-添加")
	@ApiOperation(value="加班统计-添加", notes="加班统计-添加")
	@PostMapping(value = "/addOaMonthlyOvertime")
	public Result<String> addOaMonthlyOvertime(@RequestBody OaMonthlyOvertime oaMonthlyOvertime) {
		oaMonthlyOvertimeService.save(oaMonthlyOvertime);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param oaMonthlyOvertime
	 * @return
	 */
	@AutoLog(value = "加班统计-编辑")
	@ApiOperation(value="加班统计-编辑", notes="加班统计-编辑")
	@RequestMapping(value = "/editOaMonthlyOvertime", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editOaMonthlyOvertime(@RequestBody OaMonthlyOvertime oaMonthlyOvertime) {
		oaMonthlyOvertimeService.updateById(oaMonthlyOvertime);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "加班统计-通过id删除")
	@ApiOperation(value="加班统计-通过id删除", notes="加班统计-通过id删除")
	@DeleteMapping(value = "/deleteOaMonthlyOvertime")
	public Result<String> deleteOaMonthlyOvertime(@RequestParam(name="id",required=true) String id) {
		oaMonthlyOvertimeService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "加班统计-批量删除")
	@ApiOperation(value="加班统计-批量删除", notes="加班统计-批量删除")
	@DeleteMapping(value = "/deleteBatchOaMonthlyOvertime")
	public Result<String> deleteBatchOaMonthlyOvertime(@RequestParam(name="ids",required=true) String ids) {
	    this.oaMonthlyOvertimeService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportOaMonthlyOvertime")
    public ModelAndView exportOaMonthlyOvertime(HttpServletRequest request, OaMonthlyOvertime oaMonthlyOvertime) {
		 // Step.1 组装查询条件
		 QueryWrapper<OaMonthlyOvertime> queryWrapper = QueryGenerator.initQueryWrapper(oaMonthlyOvertime, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<OaMonthlyOvertime> pageList = oaMonthlyOvertimeService.list(queryWrapper);
		 List<OaMonthlyOvertime> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "加班统计");
		 mv.addObject(NormalExcelConstants.CLASS, OaMonthlyOvertime.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("加班统计报表", "导出人:" + sysUser.getRealname(), "加班统计"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importOaMonthlyOvertime/{mainId}")
    public Result<?> importOaMonthlyOvertime(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<OaMonthlyOvertime> list = ExcelImportUtil.importExcel(file.getInputStream(), OaMonthlyOvertime.class, params);
				 for (OaMonthlyOvertime temp : list) {
                    temp.setEmployeeInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 oaMonthlyOvertimeService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-加班统计-end----------------------------------------------*/

    /*--------------------------------子表处理-已付工资记录-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	//@AutoLog(value = "已付工资记录-通过主表ID查询")
	@ApiOperation(value="已付工资记录-通过主表ID查询", notes="已付工资记录-通过主表ID查询")
	@GetMapping(value = "/listOaPaidWagesByMainId")
    public Result<IPage<OaPaidWages>> listOaPaidWagesByMainId(OaPaidWages oaPaidWages,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<OaPaidWages> queryWrapper = QueryGenerator.initQueryWrapper(oaPaidWages, req.getParameterMap());
        Page<OaPaidWages> page = new Page<OaPaidWages>(pageNo, pageSize);
        IPage<OaPaidWages> pageList = oaPaidWagesService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param oaPaidWages
	 * @return
	 */
	@AutoLog(value = "已付工资记录-添加")
	@ApiOperation(value="已付工资记录-添加", notes="已付工资记录-添加")
	@PostMapping(value = "/addOaPaidWages")
	public Result<String> addOaPaidWages(@RequestBody OaPaidWages oaPaidWages) {
		oaPaidWagesService.save(oaPaidWages);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param oaPaidWages
	 * @return
	 */
	@AutoLog(value = "已付工资记录-编辑")
	@ApiOperation(value="已付工资记录-编辑", notes="已付工资记录-编辑")
	@RequestMapping(value = "/editOaPaidWages", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editOaPaidWages(@RequestBody OaPaidWages oaPaidWages) {
		oaPaidWagesService.updateById(oaPaidWages);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "已付工资记录-通过id删除")
	@ApiOperation(value="已付工资记录-通过id删除", notes="已付工资记录-通过id删除")
	@DeleteMapping(value = "/deleteOaPaidWages")
	public Result<String> deleteOaPaidWages(@RequestParam(name="id",required=true) String id) {
		oaPaidWagesService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "已付工资记录-批量删除")
	@ApiOperation(value="已付工资记录-批量删除", notes="已付工资记录-批量删除")
	@DeleteMapping(value = "/deleteBatchOaPaidWages")
	public Result<String> deleteBatchOaPaidWages(@RequestParam(name="ids",required=true) String ids) {
	    this.oaPaidWagesService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportOaPaidWages")
    public ModelAndView exportOaPaidWages(HttpServletRequest request, OaPaidWages oaPaidWages) {
		 // Step.1 组装查询条件
		 QueryWrapper<OaPaidWages> queryWrapper = QueryGenerator.initQueryWrapper(oaPaidWages, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<OaPaidWages> pageList = oaPaidWagesService.list(queryWrapper);
		 List<OaPaidWages> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.FILE_NAME, "已付工资记录");
		 mv.addObject(NormalExcelConstants.CLASS, OaPaidWages.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("已付工资记录报表", "导出人:" + sysUser.getRealname(), "已付工资记录"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importOaPaidWages/{mainId}")
    public Result<?> importOaPaidWages(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
			 MultipartFile file = entity.getValue();
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<OaPaidWages> list = ExcelImportUtil.importExcel(file.getInputStream(), OaPaidWages.class, params);
				 for (OaPaidWages temp : list) {
                    temp.setEmployeeInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 oaPaidWagesService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.OK("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-已付工资记录-end----------------------------------------------*/




}
